package com.songkun.template.config.manager;

import android.app.Activity;

import com.songkun.template.utils.ILog;

import java.util.Stack;


/**
 * @描述: 页面管理
 * @项目名: AndroidTemplate
 * @包名: com.songkun.template.config.manager
 * @类名:
 * @作者: soongkun
 * @创建时间: 2016/4/29 13:16
 */

public class PageManager {

    private static Stack<Activity> mPageStack;

    public PageManager() {
        mPageStack = new Stack<>();
    }

    /**
     * 添加新页面
     * @param activity 页面对象
     */
    public void addPage(Activity activity) {
        if (!mPageStack.contains(activity)) {
            mPageStack.add(activity);
            ILog.e("PageManager.addPage 添加新页面:" + activity.getClass().getName());
        } else {
            ILog.e("PageManager.addPage 页面已存在");
        }
    }

    /**
     * 移除页面对象
     * @param activity 页面对象
     */
    public void removePage(Activity activity) {
        if (activity != null) {
            activity.finish();
            mPageStack.remove(activity);
            ILog.e( "PageManager.removePage 移除页面:" + activity.getClass().getName());
        }
    }

}
